const { default: axios } = require('axios')

const router = require('express').Router()


/**
 * @api {get} /ticketcinema 获取买票页面影院信息
 * @apiName 获取买票页面影院信息
 * @apiGroup buyticket(买票相关)
 * @apiDescription 获取买票页面影院信息
 * @apiVersion  1.0.0
 * 
 * @apiParam {String|Number} cinemaId=''  影院Id
 * 
 * 
 * @apiParamExample  {type} 请求示例:
 * {  
 *    cinemaId:10086,
 * }
 * 
 * @apiSuccess {Number} code 200
 * @apiSuccess {Object} datas 数据信息
 * @apiSuccessExample {type} 返回示例:
 * {
     code:200
     data: {
            cinema: {
            cinemaId: 1778,
            name: '深圳百誉影城公明上域店',
            address: '深圳市光明新区公明街道民生大道宏发荟4楼',
            longitude: 113.91400643316996,
            latitude: 22.787341631580777,
            gpsAddress: '113.91400643316996:22.787341631580777',
            cityId: 440300,
            cityName: '深圳市',
            districtId: 440311,
            districtName: '光明区',
            district: [Object],
            phone: '0755-88880033',
            telephones: [Array],
            logoUrl: 'https://pic.maizuo.comusr/1778/227c480ec2c5a51dfc235fe54d2f9ea4.png',
            businessTime: '',
            notice: '',
            isVisited: 0,
            services: [Array],
            lowPrice: 0,
            Distance: 0,
            eTicketFlag: 1,
            seatFlag: 1,
            ticketTypes: null
    }
     msg: "ok"
  },
}
 * 
 */
router.get('/ticketcinema', (req, res) => {
    let { cinemaId } = req.query
    axios('https://m.maizuo.com/gateway/', {
        params: {
            cinemaId,
        },
        headers: {
            'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.0","e":"16425891382355991425318913"}',
            'X-Host': 'mall.film-ticket.cinema.info'
        }
    }).then(datas => {
        let data = datas.data.data
        res.send({ code: 200, data, msg: 'ok' });
    })
})


/**
 * @api {get} /ticketfilm 获取买票页面影片信息
 * @apiName 获取买票页面影片信息
 * @apiGroup buyticket(买票相关)
 * @apiDescription 获取买票页面影片信息
 * @apiVersion  1.0.0
 * 
 * @apiParam {String|Number} cinemaId=''  影院Id
 * 
 * 
 * @apiParamExample  {type} 请求示例:
 * {  
 *    cinemaId:10086,
 * }
 * 
 * @apiSuccess {Number} code 200
 * @apiSuccess {Object} datas 数据信息
 * @apiSuccessExample {type} 返回示例:
 * {
     code:200
     data: {
            films: [{
                "filmId": 5859,
                "name": "长津湖之水门桥",
                "poster": "https://pic.maizuo.com/usr/movie/89689a6d36e155b697ed3e35a6c1da12.jpg",
                "actors": [
                    {
                    "name": "易烊千玺",
                    "role": "伍万里",
                    "avatarAddress": "https://pic.maizuo.com/usr/movie/f9b4b9f6f7564b4068aec8d37036459e.jpg"
                    },
                    {
                    "name": "徐克",
                    "role": "导演",
                    "avatarAddress": "https://pic.maizuo.com/usr/movie/167312fd73483b00efa169c29663d403.jpg"
                    },
                    {
                    "name": "林超贤",
                    "role": "导演",
                    "avatarAddress": "https://pic.maizuo.com/usr/movie/4033b234b72900ee8859fc739afe7e23.jpg"
                    },
                    {
                    "name": "吴京",
                    "role": "伍千里",
                    "avatarAddress": "https://pic.maizuo.com/usr/movie/0a8f4a063cce18afa5103a26577c452b.jpg"
                    },
                    {
                    "name": "陈凯歌",
                    "role": "导演",
                    "avatarAddress": "https://pic.maizuo.com/usr/movie/7c4f4a21c2bd1fea583c0abbb3e3a137.jpg"
                    }
                ],
                "director": "陈凯歌|徐克|林超贤",
                "category": "剧情|历史|战争",
                "showDate": [
                    1643817600,
                    1643904000
                ],
                "synopsis": "电影《长津湖之水门桥》以抗美援朝战争第二次战役中的长津湖战役为背景，讲述了在结束了新兴里和下碣隅里的战斗之后，七连战士们又接到了更艰巨的任务……",
                "filmType": {
                    "name": "4D",
                    "value": 13
                },
                "nation": "中国大陆",
                "language": "",
                "videoId": "",
                "premiereAt": 1643673600,
                "timeType": 3,
                "runtime": 149,
                "grade": "7.4",
                "item": {
                    "name": "4D",
                    "type": 13
                },
                "isPresale": false,
                "isSale": false
                }]
     msg: "ok"
  },
}
 * 
 */
router.get('/ticketfilm',(req,res)=>{
    let { cinemaId } = req.query
    axios('https://m.maizuo.com/gateway/', {
        params: {
            cinemaId,
        },
        headers: {
            'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.0","e":"16425891382355991425318913"}',
            'X-Host': 'mall.film-ticket.film.cinema-show-film'
        }
    }).then(datas => {
        let data = datas.data.data
        res.send({ code: 200, data, msg: 'ok' });
    })
})


/**
 * @api {get} /ticketrendercinema 获取当前日期影院情况
 * @apiName 获取当前日期影院情况
 * @apiGroup buyticket(买票相关)
 * @apiDescription 获取当前日期影院情况
 * @apiVersion  1.0.0
 * @apiParam {String|Number} filmId=''  影片Id
 * @apiParam {String|Number} cinemaId=''  影院Id
 * @apiParam {String|Number} date=''  日期(时间戳/秒)
 * 
 * 
 * @apiParamExample  {type} 请求示例:
 * {  
 *    filmId:10086,
 *    cinemaId:10086,
 *    date:1643817600
 * }
 * 
 * @apiSuccess {Number} code 200
 * @apiSuccess {Object} datas 数据信息
 * @apiSuccessExample {type} 返回示例:
 * {
     code:200
     data: {
            schedules: [{
                "advanceStopMins": 10,
                "endAt": 1643874000,
                "filmLanguage": "国语",
                "hallName": "4号厅(免费停车3小时)",
                "imagery": "2D",
                "isOnsell": true,
                "marketPrice": 9000,
                "maxSalePrice": 5190,
                "minSalePrice": 5190,
                "salePrice": 5190,
                "scheduleId": 191061598,
                "showAt": 1643867400
                }]
     msg: "ok"
  },
}
 * 
 */
router.get('/ticketrendercinema',(req,res)=>{
    let{filmId,cinemaId,date}=req.query
    axios('https://m.maizuo.com/gateway/',{
        params:{
            filmId,
            cinemaId,
            date
        },
        headers:{
            'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.0","e":"16425891382355991425318913"}',
            'X-Host': 'mall.film-ticket.schedule.list'
        }
    }).then(datas=>{
        let data = datas.data.data
        res.send({ code: 200, data, msg: 'ok' })
    })
})
module.exports = router